<div class="filter">
<?php echo $filter ?>
</div>
<div  class="box">
<table class="boxlist">
	<thead >
		<tr >
			<th style='width:40px;' class='sortable' col='track_no'>
				No.
			</th>
			<th >
				Name
			</th>
			<th >
				Album
			</th>
			<th >
				Artist
			</th>
			<th style='width:40px;' class='sortable' col='year'>
				Year
			</th>
			<th >
				Created
			</th>
			<th >
				Action
			</th>
		</tr>
	</thead>
<?php foreach ($result as $row): ?>
	<tr >
		<td >
			<?php echo $row['track_no'] ?>.
		</td>
		<td >
			<?php
				$label = $row['name'].'['.Yii::app()->params['flag']['lang'][$row['lang']].']';
				$rurl= array('admin/quickviewSong','id'=>$row['id']);
				$htmlOption = array('class'=>'colorbox');
				echo CHtml::link($label,$rurl,$htmlOption);
			?>
		</td>
		<td >
			<?php echo $row['album_name'] ?>
		</td>
		<td >
			<?php echo Fish::xr(Fish::getRow('artist',$row['artist_id']),'name') ?>
		</td>
		<td >
			<?php echo $row['year'] ?>
		</td>
		<td >
			by <?php echo Fish::xr(Fish::getRow('user',$row['user_create']),'name') ?>
			at <?php echo date('Y M d',strtotime($row['date_create'])); ?>
		</td>
		<td >
			<?php
				$label = '<button class="bt3">Edit</button>';
				$rurl= array('admin/updateSong','id'=>$row['id']);
				$htmlOption = array('style'=>'float:left;');
				echo CHtml::link($label,$rurl,$htmlOption);
			?>
			<?php echo Chtml::beginForm(array('delete'),'post',array('style'=>'float:left;')) ?>
			<input type="hidden" name="Song[id]" value="<?php echo $row['id'] ?>" />
			<?php
				$label = '<button class="bt3">Delete</button>';
				$rurl= array('admin/deleteSong','id'=>$row['id']);
				$htmlOption = array('class'=>'confirm');
				echo CHtml::link($label,$rurl,$htmlOption);
			?>
			<?php echo Chtml::endForm(); ?>
		</td>
	</tr>
<?php endforeach ?>
</table>
<?php echo $pager ?>
</div>
<script type="text/javascript" charset="utf-8">
$('select#artist_id').change(function(e){
	var target = $( this );
	if (target.val()=='') {
		$('select#album_id option').show();
	}else{
		var flag = true;
		$('select#album_id option').hide();
		$('select#album_id option').each(function(e){
			var option = $( this );
			if ( option.val()=='' || option.attr('artist_id') == target.val()) {
				if (flag) {$('select#album_id').val(option.val());flag=false;};
				option.show();
			}
		});
	}
});
</script>